// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SourceFile

package com.sgame.android.data;

import com.sgame.android.data.TunnelTransmittable;
import java.util.*;
import java.util.Map.Entry;

import org.json.*;

public final class Tunnel
{

    public static String toString(String s, JSONObject jsonobject)
    {
        return (new StringBuilder()).append(s).append("Factory_delayed(").append(jsonobject.toString()).append(")").toString();
    }

    public static String toString(String s, Map<String,JSONArray> map)
    {
        s = new String((new StringBuilder()).append(s).append("Factory_delayed({").toString());
        boolean flag = true;
        Iterator<Entry<String, JSONArray>> item;
        Object val;
        for(item = map.entrySet().iterator(); item.hasNext();)
        {
        	java.util.Map.Entry<String, JSONArray> obj = (java.util.Map.Entry<String, JSONArray>)item.next();
            if(flag)
                flag = false;
            else
                s = (new StringBuilder()).append(s).append(",").toString();
            s = (new StringBuilder()).append(s).append(JSONObject.quote((String)obj.getKey())).toString();
            s = (new StringBuilder()).append(s).append(":").toString();
            if((val = obj.getValue()) instanceof TunnelTransmittable)
                s = (new StringBuilder()).append(s).append(((TunnelTransmittable)obj).toJsonStringForTunnel()).toString();
            else
            if(val instanceof JSONArray)
                s = (new StringBuilder()).append(s).append(val.toString()).toString();
            else
                s = (new StringBuilder()).append(s).append(JSONObject.quote(val != null ? val.toString() : null)).toString();
        }

        return (new StringBuilder()).append(s).append("})").toString();
    }

    public static Map<String,String> getMap(JSONObject jsonobject, String s, String s1)
    {
        HashMap<String,String> hashmap = new HashMap<String,String>();
        JSONArray jsonarray = jsonobject.optJSONArray(s);
        JSONArray jsonarray1 = jsonobject.optJSONArray(s1);
        if(jsonarray != null && jsonarray1 != null && jsonarray.length() == jsonarray1.length())
            try
            {
                for(int j = 0; j < jsonarray.length(); j++)
                    hashmap.put(jsonarray.getString(j), jsonarray1.getString(j));

            }
            catch (JSONException e) {
                throw new RuntimeException(e);
			}
        else
            throw new RuntimeException((new StringBuilder("Array Pair ")).append(s).append(",").append(s1).append(" cannot be converted into a HashMap in json ").append(jsonobject).toString());
        return hashmap;
    }

    public static void Add(Map<String,JSONArray> map, Map<String,JSONArray> map1, String s, String s1)
    {
        JSONArray jsonarray = new JSONArray();
        JSONArray jsonarray1 = new JSONArray();
        java.util.Map.Entry<String, JSONArray> entry;
        Iterator<Entry<String, JSONArray>> item;
        for(item = map.entrySet().iterator(); item.hasNext(); jsonarray1.put(entry.getValue()))
        {
            entry = (java.util.Map.Entry<String, JSONArray>)item.next();
            jsonarray.put(entry.getKey());
        }

        map1.put(s, jsonarray);
        map1.put(s1, jsonarray1);
    }
}
